// 这个文只是用于解释react-loadable原理用，当然可以无缝切换
import React, { Component } from 'react'

const Loadable = ({
    loader,
    loading:Loading
}) =>{
    return class LoadableComponent extends Component {
        state={
            LoadedComponent: null
        }
        componentDidMount(){
            loader()
            .then(resp =>{
              this.setState({
                  LoadableComponent:resp.default
              })
                
            })
        }
        render (){
            const {
                LoadedComponent
            } = this.state
            return (
                this.state.LoadableComponent ?
                <LoadableComponent/> :
                <Loading />
                )
        }
    }
}

export default Loadable